home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 031a / blx11.zip / WHELLO.C < prev    next >
C/C++ Source or Header  |  1991-01-23  |  2KB  |  91 lines

  1. /* whello.c
  2.  */
  3.  
  4. #include<windows.h>
  5.  
  6.  
  7. long FAR PASCAL WndProc(HWND, WORD, WORD, LONG);
  8.  
  9. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  10.     LPSTR lpCmdLine, int nCmdShow)
  11.     {
  12.     static char szAppName[] = "HelloWin";
  13.     HWND hWnd;
  14.     MSG msg;
  15.     WNDCLASS wndclass;
  16.  
  17.     if(!hPrevInstance)    
  18.         {
  19.         wndclass.style = NULL;
  20.         wndclass.lpfnWndProc = WndProc;
  21.         wndclass.cbClsExtra = 0;       
  22.         wndclass.cbWndExtra = 0;       
  23.         wndclass.hInstance = hInstance;
  24.         wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  25.         wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  26.         wndclass.hbrBackground = GetStockObject(WHITE_BRUSH); 
  27.         wndclass.lpszMenuName =  NULL;
  28.         wndclass.lpszClassName = szAppName;
  29.  
  30.         RegisterClass(&wndclass);
  31.         }
  32.  
  33.     hWnd = CreateWindow(szAppName,
  34.         "Hello Program",
  35.         WS_OVERLAPPEDWINDOW,            
  36.         CW_USEDEFAULT,                  
  37.         CW_USEDEFAULT,                  
  38.         CW_USEDEFAULT,                  
  39.         CW_USEDEFAULT,                  
  40.         NULL,                           
  41.         NULL,                           
  42.         hInstance,                      
  43.         NULL);
  44.  
  45.     ShowWindow(hWnd, nCmdShow);
  46.     UpdateWindow(hWnd);        
  47.  
  48.     while(GetMessage(&msg, NULL, 0, 0))
  49.         {
  50.         TranslateMessage(&msg);
  51.         DispatchMessage(&msg); 
  52.         }
  53.     return (msg.wParam);  
  54. }
  55.  
  56.  
  57. long FAR PASCAL WndProc(HWND hWnd, WORD message,
  58.     WORD wParam, LONG lParam)
  59.     {
  60.     char *text = "Hello, World!";
  61.  
  62.     switch(message)
  63.         {
  64.         case WM_PAINT:
  65.             {
  66.             PAINTSTRUCT ps;
  67.             RECT rect;
  68.  
  69.             HDC hdc = BeginPaint(hWnd, &ps);
  70.  
  71.             GetClientRect(hWnd,&rect);
  72.  
  73.             TextOut(ps.hdc, rect.right/2, rect.bottom/2, (LPSTR)text,
  74.                 strlen(text));
  75.  
  76.             EndPaint(hWnd, &ps);
  77.             }
  78.             break;
  79.  
  80.         case WM_CLOSE:
  81.             DestroyWindow(hWnd);
  82.             break;
  83.  
  84.         case WM_DESTROY:
  85.             PostQuitMessage(0);
  86.             break;
  87.         }
  88.     return DefWindowProc(hWnd, message, wParam, lParam);
  89.     }
  90.  
  91.